package com.yycx.module.bus.provider.handler.export;

import cn.hutool.core.map.MapUtil;
import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.base.module.export.ExportField;
import com.yycx.common.mybatis.interceptor.ExportInterceptor;
import com.yycx.common.mybatis.model.ResultBody;
import com.yycx.module.bus.provider.service.hy.HyErpSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * 导出综合查询
 *
 * @author zyf
 */
@Component
public class ExportListHandler implements ExportInterceptor {

    @Autowired
    private HyErpSearchService hyErpSearchService;

    @Override
    public ResultBody initData(Map params) {
        String dbName = MapUtil.getStr(params, "dbName");
        String exportTag = MapUtil.getStr(params, "exportTag");
        if ("1".equals(exportTag)) {
            return hyErpSearchService.procureList(dbName, params, false);
        }
        if ("2".equals(exportTag)) {
            return hyErpSearchService.procureDetailList(dbName, params, false);
        }
        if ("3".equals(exportTag)) {
            return hyErpSearchService.saleList(dbName, params, false);
        }
        if ("4".equals(exportTag)) {
            return hyErpSearchService.saleDetailList(dbName, params, false);
        }
        if ("5".equals(exportTag)) {
            return hyErpSearchService.mxzList(dbName, params, false);
        }
        return ResultBody.ok();
    }

    @Override
    public void initExcelExportEntity(ExportField exportField, List list) {
        Object key = exportField.getKey();
        exportField.setWidth(12);
    }
}
